package com.coder.books.thinkinjava.music3;


import static com.coder.util.Print.print;
import static com.coder.util.Print.println;

/**
 * 音符
 */
enum Note {
    MIDDLE_C, C_SHARP, B_FLAT
}

/**
 * 乐器
 */
class Instrument {
    void play(Note n) {
        print("Instrument.play() " + n);
    }

    String what() {
        return "Instrument";
    }

    void adjust() {
        println("Adjusting Instrument");
    }
}

/**
 * 管乐器
 */
class Wind extends Instrument {
    @Override
    void play(Note n) {
        println("Wind.play() " + n);
    }

    @Override
    String what() {
        return "Wind";
    }

    @Override
    void adjust() {
        println("Adjusting Wind");
    }
}

/**
 * 打击乐器
 */
class Percussion extends Instrument {
    @Override
    void play(Note n) {
        println("Percussion.play() " + n);
    }

    @Override
    String what() {
        return "Percussion";
    }

    @Override
    void adjust() {
        println("Adjusting Percussion");
    }
}

/**
 * 弦乐器
 */
class Stringed extends Instrument {
    @Override
    void play(Note n) {
        println("Stringed.play() " + n);
    }

    @Override
    String what() {
        return "Stringed";
    }

    @Override
    void adjust() {
        println("Adjusting Stringed");
    }
}

/**
 * 铜管乐器
 */
class Brass extends Wind {
    @Override
    void play(Note n) {
        println("Brass.play() " + n);
    }

    @Override
    void adjust() {
        println("Adjusting Brass");
    }
}

/**
 * 木管乐器
 */
class Woodwind extends Wind {
    @Override
    void play(Note n) {
        println("Woodwind.play() " + n);
    }

    @Override
    String what() {
        return "Woodwind";
    }
}

/**
 * 音乐
 *
 * @author yuhushuan
 * @date 2020/7/22 21:26
 */

public class Music3 {
    public static void tune(Instrument i) {
        i.play(Note.MIDDLE_C);
    }

    public static void tuneAll(Instrument[] e) {
        for (Instrument i : e) {
            tune(i);
        }
    }

    public static void main(String[] args) {
        // 在添加到序列期间进行向上转型
        Instrument[] orchestra = {
                new Wind(),
                new Percussion(),
                new Stringed(),
                new Brass(),
                new Woodwind()
        };
        tuneAll(orchestra);
    }
}


